package edu.java.homework.hw03.ipj06;

import java.util.Scanner;

/**
 * Tsvetan's solution of Exercise 01 in IPJ web site, section UP, lecture 6 This
 * exercise is concentrate on working with arrays
 * 
 * @author Tsvetan Vasilev
 * 
 */
public class Exercise01done {

    public static void main(String[] args) {
	System.out.println("Please, enter the count of elements of the array");
	int elementsCount = 0;

	Scanner input = new Scanner(System.in);
	System.out.println("Elements count: ");
	elementsCount = input.nextInt();
	if (elementsCount < 1) {
	    throw new IllegalArgumentException("Incorrect count of elements");
	}

	int[] a = new int[elementsCount];
	init(a);
	print(a);

	input.close();

    }

    /*
     * 1a)Да се напишат метод със следната сигнатура и спецификация : public
     * static void init(int[] a), който да инициализира едномерен масив със
     * стойности въведени от клавиатурата;
     */
    /**
     * initialize a one-dimentional array
     * 
     * @param one
     *            - dimentional array
     * @throws IllegalArgumentException
     */
    public static void init(int[] a) {
	if (a == null) {
	    throw new IllegalArgumentException("The array is null-pointed");
	}

	Scanner input = new Scanner(System.in);
	for (int index = 0; index < a.length; index++) {
	    System.out.print("a[" + index + "]= ");
	    a[index] = input.nextInt();
	    System.out.println();
	}
	input.close();
    }

    /*
     * 1б) public static void print(int[] a), който да отпечатва на екрана
     * стойностите на едномерен масив във вид на редица;
     */

    /**
     * print one-dimentional array
     * 
     * @param one
     *            -dimentional array
     * @throws IllegalArgumentException
     */
    public static void print(int[] a) {
	if (a == null) {
	    throw new IllegalArgumentException("The array is null-pointed");
	}
	for (int index = 0; index < a.length; index++) {
	    System.out.print(a[index] + "  ");
	}
    }

    public static void init(int[][] a) {
	System.out
		.println("Please, enter the dimentions of the two-dimensional array");
	int rowCount = 0;
	int columnCount = 0;
	Scanner input = new Scanner(System.in);
	System.out.println("Row count: ");
	rowCount = input.nextInt();
	System.out.println("Column count: ");
	columnCount = input.nextInt();
	if (rowCount < 2 || columnCount < 2) {
	    throw new IllegalArgumentException(
		    "Incorrect count of rows/columns");
	}

	a = new int[rowCount][columnCount];

    }

}
